
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
<script src="/js/jquery.ajaxupload.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/blitzer/jquery-ui.min.css"/>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
<![endif]-->
<script type="text/javascript">
	$(window).ready(function(){
		$('#inputDate').datepicker({
			dateFormat: 'yy-mm-dd',
		});
	});
</script>
<script type="text/javascript">
	jQuery(function ($) {
        // Set fieldname
        $.ajaxUploadSettings.name = 'uploads[]';
        // Set promptzone
        $('#outside a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'outside'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#outside').find('input#file_outside').val(data['filename']);
		        $('#outside').find('img').attr('src', data['file']);
	        }
        });
        $('#before a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'before'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#before').find('input#file_before').val(data['filename']);
		        $('#before').find('img').attr('src', data['file']);
	        }
        });
        $('#after a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'after'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#after').find('input#file_after').val(data['filename']);
		        $('#after').find('img').attr('src', data['file']);
	        }
        });
        $('#display a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'display'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#display').find('input#file_display').val(data['filename']);
		        $('#display').find('img').attr('src', data['file']);
	        }
        });
        $('#optional a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'optional'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#optional').find('input#file_optional').val(data['filename']);
		        $('#optional').find('img').attr('src', data['file']);
	        }
        });
        $('#staff a').ajaxUploadPrompt({
        	method : 'POST',
        	data: {"photo": 'staff'},
		    processData: false,
		    contentType: 'application/json',
	        url : '/contact/upload',
	        beforeSend : function () {
	        },
	        onprogress : function (e) {
	        },
	        error : function () {
	        },
	        success : function (data) {
		        data = $.parseJSON(data);
		        $('#staff').find('input#file_staff').val(data['filename']);
		        $('#staff').find('img').attr('src', data['file']);
	        }
        });
	});
</script>

<form class="form" action="" role="form" method="POST" enctype="multipart/form-data">
	<div class="col-lg-12">
	<div class="row">
		<div class="col-lg-6 col-sm-12">
			<div class="form-group">
				<label class="control-label" for="inputName">Store Name</label>
				<div class="controls">
					<input class="form-control" name="data[store_id]" type="text" id="inputName" value="<?php echo $distributor->title;?>" disabled="disabled">
				</div>
			</div>
			<div class="form-group">
				<label class="control-label" for="inputDate">Date</label>
				<div class="controls">
					<input class="form-control" name="data[log_date]" type="text" id="inputDate" value="<?php echo date('Y-m-d', strtotime($contact_log->log_date));?>">
				</div>
			</div>
			<div class="form-group">
				<label class="control-label" for="inputMethod">Contact Method</label>
				<div class="controls">
					<select class="form-control" name="data[contact_method]" id="inputMethod">
						<option <?php if ($contact_log->contact_method == 1){ echo 'selected="selected"';}?> value="1">Visited</option>
						<option <?php if ($contact_log->contact_method == 2){ echo 'selected="selected"';}?> value="2">Phoned</option>
						<option <?php if ($contact_log->contact_method == 3){ echo 'selected="selected"';}?> value="3">Received a call from</option>
						<option <?php if ($contact_log->contact_method == 4){ echo 'selected="selected"';}?> value="4">Cold Called</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label" for="inputReason">Contact Reason</label>
				<div class="controls">
					<select class="form-control" name="data[contact_reason]" id="inputReason">
						<option <?php if ($contact_log->contact_reason == 1){ echo 'selected="selected"';}?> value="1">Training & Merchandising</option>
						<option <?php if ($contact_log->contact_reason == 2){ echo 'selected="selected"';}?> value="2">Courtesy Call</option>
						<option <?php if ($contact_log->contact_reason == 3){ echo 'selected="selected"';}?> value="3">Returning Call</option>
						<option <?php if ($contact_log->contact_reason == 4){ echo 'selected="selected"';}?> value="4">Store phoned office</option>
						<option <?php if ($contact_log->contact_reason == 5){ echo 'selected="selected"';}?> value="5">Merchandising</option>
						<option <?php if ($contact_log->contact_reason == 6){ echo 'selected="selected"';}?> value="6">Other</option>
						<option <?php if ($contact_log->contact_reason == 7){ echo 'selected="selected"';}?> value="7">Cold Call</option>
						<option <?php if ($contact_log->contact_reason == 8){ echo 'selected="selected"';}?> value="8">Training</option>
					</select>
				</div>
			</div>
            <div class="form-group">
                <label class="control-label" style="text-align: left;" for="inputComment">Contact Comment</label>
    			<textarea class="form-control" name="data[contact_comment]" rows="7" required><?php echo $contact_log->contact_comment?></textarea>
            </div>
		</div>
		<div class="col-lg-6 col-sm-12" id="outside">
			<?php $sql1 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 1";
                $result1 = Photos::model()->findBySql($sql1);
                    if($result1 != ''){ ?>
        	        	<input type="hidden" name="photos[outside]" value="" id="file_outside">
                        <input type="hidden" name="data[tmp_outside]" value="<?php echo $result1->id; ?>" />        	            <div align="center"><strong>Outside</strong></div>
        	            <a class="thumbnail" href="#">
                           <img class="img-rounded" src="/public/photos/<?php echo $result1->name ?>"/>
                        </a>
                    <?php }else{ ?>
        	        	<input type="hidden" name="photos[outside]" value="" id="file_outside">
        	            <div align="center"><strong>Outside</strong></div>
        	            <a class="thumbnail" href="#">
                           <img class="img-rounded" src="/images/upload-photo.png"/>
                        </a>
                    <?php } ?>
                <p><input type="checkbox" value="1" name="data[profile]" <?php if($contact_log->is_profile ==1 ) echo "checked"; ?>  /> Make Profile Pics</p>
		</div>
	</div>
	</div>
	<div class="col-lg-12">
	<div id="photos" class="row" style="margin-top: 30px;">
	    <h2>Photos (optional)</h2>
	    <div class="row-fluid">
                <?php $sql2 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 2";
                $result2 = Photos::model()->findBySql($sql2); 
                if($result2 != ''){ ?>
    	        <div id="before" style="width: 19%; float: left; margin-right: 10px;">
    	        	<input type="hidden" name="photos[before]" value="" id="file_before">
                    <input type="hidden" name="data[tmp_before]" value="<?php echo $result2->id; ?>" />
    	            <div align="center"><strong>Before</strong></div>
    	            <a class="thumbnail" href="#">
                        <img class="img-rounded" src="/public/photos/<?php echo $result2->name ?>"/>
                    </a>
					</p>
        	            <p align="center"><img src="../../../../../images/delete pic.jpg"  alt="" width="30" height="30" align="left"/><img src="../../../../../images/rotate image.png" width="50" height="50"  alt=""/>Rotate pic</p>
        	            <p align="center">&nbsp;</p>
    	        </div>
                <?php }else{ ?>
                    <div id="before" style="width: 19%; float: left; margin-right: 10px;">
        	        	<input type="hidden" name="photos[before]" value="" id="file_before">
        	            <div align="center"><strong>Before</strong></div>
        	            <p><a class="thumbnail" href="#">
        	              <img class="img-rounded" src="/images/upload-photo.png"/>
       	                </a>
                   </div>
                <?php } ?>
                
                
                 <?php $sql3 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 3";
                    $result3 = Photos::model()->findBySql($sql3); 
                    if($result3 != ''){ ?> 
        	        <div id="after" style="width: 19%; float: left; margin-right: 10px;">
        	        	<input type="hidden" name="photos[after]" value="" id="file_after">
                        <input type="hidden" name="data[tmp_after]" value="<?php echo $result3->id; ?>" />
        	            <div align="center"><strong>After</strong></div>
        	            <a class="thumbnail" href="#">
                               <img class="img-rounded" src="/public/photos/<?php echo $result3->name ?>"/>
                        </a>
						<p align="center"><img src="../../../../../images/delete pic.jpg"  alt="" width="30" height="30" align="left"/><img src="../../../../../images/rotate image.png" width="50" height="50"  alt=""/>Rotate pic</p>
        	            <p align="center">&nbsp;</p>
        	        </div>
                    <?php }else{ ?>
                        <div id="after" style="width: 19%; float: left; margin-right: 10px;">
        	        	<input type="hidden" name="photos[after]" value="" id="file_after">
        	            <div align="center"><strong>After</strong></div>
        	            <p><a class="thumbnail" href="#">
        	              <img class="img-rounded" src="/images/upload-photo.png"/>
       	                </a>
      	              </p>
        	                 
                    </div>
                    <?php } ?>
            
            
                    
                <?php $sql4 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 4";
                    $result4 = Photos::model()->findBySql($sql4); 
                    if($result4 != ''){ ?>
        	        <div id="display" style="width: 19%; float: left; margin-right: 10px;">
        	        	<input type="hidden" name="photos[display]" value="" id="file_display">
                        <input type="hidden" name="data[tmp_display]" value="<?php echo $result4->id; ?>" />
        	            <div align="center"><strong>Display 1</strong></div>
        	            <a class="thumbnail" href="#"> 
                            <img class="img-rounded" src="/public/photos/<?php echo $result4->name ?>"/>
                        </a>
						<p align="center"><img src="../../../../../images/delete pic.jpg"  alt="" width="30" height="30" align="left"/><img src="../../../../../images/rotate image.png" width="50" height="50"  alt=""/>Rotate pic</p>
        	            <p align="center">&nbsp;</p>
        	        </div>
                    <?php }else{ ?>
                    <div id="display" style="width: 19%; float: left; margin-right: 10px;">
        	        	<input type="hidden" name="photos[display]" value="" id="file_display">
        	            <div align="center"><strong>Display 1</strong></div>
       	              <p><a class="thumbnail" href="#"> 
        	              <img class="img-rounded" src="/images/upload-photo.png"/>
       	                </a>
      	              </p>
        	            
                    </div>
                    <?php } ?>
                    
                    
                <?php $sql5 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 5";
                    $result5 = Photos::model()->findBySql($sql5);
                     if($result5 != ''){ ?>
            	        <div id="optional" style="width: 19%; float: left; margin-right: 10px;">
            	        	<input type="hidden" name="photos[optional]" value="" id="file_optional">
                            <input type="hidden" name="data[tmp_optional]" value="<?php echo $result5->id; ?>" />
            	            <div align="center"><strong>Optional</strong></div>
            	            <a class="thumbnail" href="#">
                                <img class="img-rounded" src="/public/photos/<?php echo $result5->name ?>"/>
                            </a>
							<p align="center"><img src="../../../../../images/delete pic.jpg"  alt="" width="30" height="30" align="left"/><img src="../../../../../images/rotate image.png" width="50" height="50"  alt=""/>Rotate pic</p>
							<p align="center">&nbsp;</p>
            	        </div>
                    <?php }else{ ?>
                        <div id="optional" style="width: 19%; float: left; margin-right: 10px;">
            	        	<input type="hidden" name="photos[optional]" value="" id="file_optional">
            	            <div align="center"><strong>Optional</strong></div>
            	            <p><a class="thumbnail" href="#">
            	              <img class="img-rounded" src="/images/upload-photo.png"/>
           	                </a>
          	              </p>  
                        </div>
                    <?php } ?>
                
                
                     <?php $sql6 = "SELECT * FROM photos WHERE contact_log_id = ".$contact_log->id ." AND photo_type = 6";
                     $result6 = Photos::model()->findBySql($sql6);
                     if($result6 != ''){ ?>
            	        <div id="staff" style="width: 19%; float: left;">
            	        	<input type="hidden" name="photos[staff]" value="" id="file_staff">
                            <input type="hidden" name="data[tmp_staff]" value="<?php echo $result6->id; ?>" />
            	            <div align="center"><strong>Staff</strong></div>
            	            <a class="thumbnail" href="#">
                                <img class="img-rounded" src="/public/photos/<?php echo $result6->name ?>"/>
                            </a>
							<p align="center"><img src="../../../../../images/delete pic.jpg"  alt="" width="30" height="30" align="left"/><img src="../../../../../images/rotate image.png" width="50" height="50"  alt=""/>Rotate pic</p>
							<p align="center">&nbsp;</p>
            	        </div>
                    <?php }else{ ?>
                        <div id="staff" style="width: 19%; float: left;">
            	        	<input type="hidden" name="photos[staff]" value="" id="file_staff">
            	            <div align="center"><strong>Staff</strong></div>
            	            <p>
								<a class="thumbnail" href="#">
									<img class="img-rounded" src="/images/upload-photo.png"/>
								</a>
							</p>
                        </div>
                    <?php } ?>
	    </div>
        
	</div>
	</div>
    <div class="col-lg-12">
        <p><input type="checkbox" <?php if($profile_all == 1) echo "checked"; ?> value="1" name="data[profile_all]" /> Make Profile Pics</p>
       
    </div>
	<div class="col-lg-12" style="text-align: center;">
		<p><button type="submit" name="data[action]" value="save" class="btn btn-primary">Edit Contact Log</button>
		<?php if ($contact_log->status == 0){?>
			<button type="submit" name="data[action]" value="draft" class="btn">Save Draft</button>
		<?php }?>
        <a href="/distributors/view/<?php echo $contact_log->distributor_id; ?>" type="submit" name="data[action]" value="save" class="btn btn-primary">Return to store profile</a></p>
	</div>
</form>